<?php

require 'facebook.php';
require 'config.inc.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => $fbconfig['app_id'],
  'secret' => $fbconfig['secret_key'],
  'cookie' => true,
));

$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
  } catch (FacebookApiException $e) {
    echo "false";
  }
}

$uid = $_POST["uid"];
$access_token = $_POST["access_token"];
$groupid= $_POST["xid"];
$friendid= $_POST["fid"];

$con = mysql_connect("localhost", "vatsav", "2T*vzcd");
if (!$con)
{
  echo('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("vatsav", $con);
if (!$db_selected) {
	die ('Cant use db : ' . mysql_error());
}

$result = mysql_query('insert into members values('.$uid.','.$groupid.','.$friendid.')');	
// Check result
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   echo($message);
}

$result = mysql_query('delete from invitations where uid='.$uid.' and groupid='.$groupid.' and friendid='.$friendid);	
// Check result
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   echo($message);
}
mysql_close($con);
echo "true";
?>